﻿#if UNITY_EDITOR
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
/// <summary>
/// 工程设定窗口
/// </summary>
public class EditorWindow_ProjectSetting : AbsESF_EditorWindow
{
    /// <summary>
    /// 菜单方法组
    /// </summary>
    Dictionary<MethodInfo, ESF_ProjectSettingMenuItemAttribute> mMenuItemMethods = new Dictionary<MethodInfo, ESF_ProjectSettingMenuItemAttribute>();
    /// <summary>
    /// 快捷按钮组
    /// </summary>
    Dictionary<MethodInfo, ESF_ProjectQuickButtonAttribute> mQuickButtons = new Dictionary<MethodInfo, ESF_ProjectQuickButtonAttribute>();

    /// <summary>
    /// 滚动视力位置
    /// </summary>
    Vector2 mScrollViewPosition = Vector2.zero;

    protected override AbsESF_EditorBuildAsset config => ESF_Logic.projectSetting;

    /// <summary>
    /// OnFocus
    /// </summary>
    private void OnFocus()
    {
        mQuickButtons = ESF_Logic.GetProjectQuickButton();
    }

    /// <summary>
    /// OnGUI
    /// </summary>
    protected override void OnRunGUI()
    {
        if (GUILayout.Button(ESF_enGUIDisplayWord.Save.ESF_ToAlias()))
        {
            OnSaveConfig();
        }
        if (GUILayout.Button($"{ESF_enGUIDisplayWord.Load.ESF_ToAlias()}{ESF_enGUIDisplayWord.MenuItem.ESF_ToAlias()}"))
        {
            mMenuItemMethods = ESF_Logic.GetProjectSettingMenuItem();
        }
        ESF_Utility.DrawSeparator();
        mScrollViewPosition = EditorGUILayout.BeginScrollView(mScrollViewPosition);
        foreach (var key in mMenuItemMethods)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button($"【{key.Value.menuDesc}】{key.Value.menuName}"))
            {
                key.Key?.Invoke(null, null);
            }
            EditorGUILayout.EndHorizontal();
        }
        EditorGUILayout.EndScrollView();
        ESF_Utility.DrawSeparator();
        foreach (var key in mQuickButtons)
        {
            if (GUILayout.Button($"{key.Value.desc}"))
            {
                key.Key?.Invoke(null, null);
            }
        }
        ESF_Utility.DrawSeparator();       
    }
}
#endif
